package com.hxd.otc.module.convenience.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.module.convenience.bean.ConvenienceOrderBean;
import com.hxd.otc.module.convenience.contract.ConvenienceOrderDetailContract;
import com.hxd.otc.module.convenience.presenter.ConvenienceOrderDetailPresenter;
import com.hxd.otc.utils.AddressUtil;
import com.hxd.otc.utils.StringUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class ConvenienceOrderDetailActivity extends BaseActivity<ConvenienceOrderDetailPresenter> implements ConvenienceOrderDetailContract.IView {

    @BindView(R.id.tv_nums)
    TextView tvNums;

    @BindView(R.id.tv_coin_type)
    TextView tvCoinType;

    @BindView(R.id.tv_coin_operate)
    TextView tvCoinOperate;

    @BindView(R.id.tv_order_number)
    TextView tvOrderNumber;

    @BindView(R.id.tv_order_info)
    TextView tv0rderInfo;

    @BindView(R.id.tv_order_money)
    TextView tvOrderMoney;

    @BindView(R.id.tv_statues)
    TextView tvStatues;

    @BindView(R.id.tv_charge_account)
    TextView tvChargeAccount;

    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;

    ConvenienceOrderBean orderBean;
    String[] statuusType;

    public static final String EXTRA_INFO = "info";
    public static final String EXTRA_ID = "id";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_convenience_order_detail;
    }

    @Override
    protected ConvenienceOrderDetailPresenter createPresenter() {
        return new ConvenienceOrderDetailPresenter(this);
    }

    @Override
    protected void initView() {
        String id = getBundle().getString(EXTRA_ID);
        if (!TextUtils.isEmpty(id)) {
            mPresenter.requestOrderDetail(id);
        } else {
            orderBean = (ConvenienceOrderBean) getBundle().getSerializable(EXTRA_INFO);
            updateUI();
        }
    }

    private void updateUI() {
        statuusType = getResources().getStringArray(R.array.convenience_order_statues);
        tvNums.setText(StringUtil.handleZero(orderBean.getVolume()));
        tvCoinType.setText(orderBean.getSymbol());
        tvOrderNumber.setText(orderBean.getId());
        tv0rderInfo.setText(orderBean.getGoodsName());
        tvOrderMoney.setText(String.format("%s %s", StringUtil.handleZero(orderBean.getSellPrice()), orderBean.getPriceUnit()));
        tvStatues.setText(statuusType[orderBean.getStatus()]);
        tvOrderTime.setText(orderBean.getUpdateDate());
        tvChargeAccount.setText(orderBean.getRechargeAccount());
        tvCoinOperate.setText(statuusType[orderBean.getStatus()]);
    }

    @Override
    public void getOrderDetailSuccess(ConvenienceOrderBean convenienceOrderData) {
        orderBean = convenienceOrderData;
        updateUI();
    }

    @OnClick({R.id.tv_order_number})
    public void onClick(View view) {
        AddressUtil.copyAddress(this, tvOrderNumber.getText().toString(), getString(R.string.the_order_number_was_copied_successfully));
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void initEvent() {

    }
}
